package com.caration.shell.action;

import com.caration.shell.Home;
import com.caration.shell.R;
import com.caration.shell.config.CommonConfig;
import com.caration.shell.preference.SettingPreferenceActivity;

import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.speech.RecognizerIntent;

import java.util.ArrayList;

public final class CommandsHelper {
	public static ArrayList<Command> sCommands;
	private static boolean b;
	private static boolean c;

	public static String getNameFromId(Context context, int id) {
		String name = "";
		switch (id) {
		case Command.CMD_NONE:
			name = context.getString(R.string.none);
			break;
		case Command.CMD_APP_DRAWER:
			name = context.getString(R.string.mn_action_app_drawer);
			break;
		case Command.CMD_HOME_DESKTOP:
			name = context.getString(R.string.mn_action_home_screen);
			break;
		case Command.CMD_SWITCH_DRAWER_HOME:
			name = context
					.getString(R.string.mn_action_switch_appdrawer_homescreen);
			break;
		case Command.CMD_TOGGLE_NOTIBAR:
			name = context
					.getString(R.string.mn_action_toggle_notification_bar);
			break;
		case Command.CMD_EXPAND_NOTIBAR:
			name = context
					.getString(R.string.mn_action_expand_notification_bar);
			break;
		case Command.CMD_TOGGLE_MENU:
			name = context.getString(R.string.mn_action_toggle_menu_bar);
			break;
		case Command.CMD_EXPAND_MENU:
			name = context.getString(R.string.mn_action_expand_shrink_menu_bar);
			break;
		case Command.CMD_TEXT_SEARCH:
			name = context.getString(R.string.mn_action_text_search);
			break;
		case Command.CMD_VOICE_SEARCH:
			name = context.getString(R.string.mn_action_voice_search);
			break;
		case Command.CMD_SHELL_SETTING:
			name = context.getString(R.string.mn_action_cr_settings);
			break;
		}
		return name;
	}

	public static String makeCommand(Context context, int i, int j) {
		return (new StringBuilder(String.valueOf(i))).append(",'")
				.append(getNameFromId(context, j)).append("','caration://")
				.append(j).append("'").toString();
	}

	public static void execute(int id) {
		switch (id) {
		case Command.CMD_APP_DRAWER: // '\001' app drawer
			// fm.h().s();
			break;

		case Command.CMD_HOME_DESKTOP: // '\002' home
			// fm.h().t();
			break;

		case Command.CMD_SWITCH_DRAWER_HOME: // '\003' switch home/drawer
			// fm.h().u();
			break;

		case Command.CMD_TOGGLE_NOTIBAR: // '\004' toggle noti
			// r r1 = new r();
			// com.censivn.C3DEngine.a.a();
			// w.a(r1);
			break;

		case Command.CMD_EXPAND_NOTIBAR: // '\005' expend noti
			// s s1 = new s();
			// com.censivn.C3DEngine.a.a();
			// w.a(s1);
			break;

		case Command.CMD_TOGGLE_MENU: // '\006' toggle menu
			// fm.k().a();
			break;
		case Command.CMD_EXPAND_MENU: // '\n' expand menu
			// fm.k().b();
			break;
		case Command.CMD_TEXT_SEARCH: // '\007' text search
			Intent textSearch = new Intent(
					SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
			Home.getInstance().startActivity(textSearch);
			break;

		case Command.CMD_VOICE_SEARCH: // '\b' voice search
			Intent voiceSearch = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
			Home.getInstance().startActivity(voiceSearch);
			break;

		case Command.CMD_SHELL_SETTING: // '\t' shell setting
			SettingPreferenceActivity.startup();
			break;
		}
	}

	public static void a(boolean flag) {
		boolean flag1 = false;
		if (!flag) {
			android.view.WindowManager.LayoutParams layoutparams = Home
					.getInstance().getWindow().getAttributes();
			layoutparams.flags = 0xfffffbff & layoutparams.flags;
			Home.getInstance().getWindow().setAttributes(layoutparams);
			Home.getInstance().getWindow().clearFlags(512);
			b = false;
		} else {
			android.view.WindowManager.LayoutParams layoutparams1 = Home
					.getInstance().getWindow().getAttributes();
			layoutparams1.flags = 0x400 | layoutparams1.flags;
			Home.getInstance().getWindow().setAttributes(layoutparams1);
			Home.getInstance().getWindow().addFlags(512);
			b = true;
		}
		if (!b)
			flag1 = true;
		CommonConfig.setNotificationStatus(Boolean.valueOf(flag1));
	}

	static boolean a() {
		return b;
	}

	static void b() {
		c = true;
	}

	public static void b(boolean flag) {
		if (c && flag) {
			a(true);
			c = false;
		}
	}
}
